from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import classification_report

iris = datasets.load_iris()
X = iris.data
y = iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)

DTC = DecisionTreeClassifier()
DTC.fit(X_train, y_train)
print(iris.feature_names)
# 输出特征重要性
print(DTC.feature_importances_)

score = DTC.score(X_test, y_test)
print(score)
print(classification_report(y_test, DTC.predict(X_test)))

